package com.gen.com;

import java.util.ArrayList;

import com.gen.asynTask.*;
import com.gen.service.RefreshGameRoomManagerService;
import com.gen.tool.AlertDialog_ok;
import com.gen.tool.AlertDialog_ok_cancel;
import com.gen.tool.PlayerInfo;
import com.gen.tool.SoundPlayer;
import com.ouken.com.LoginActivity;
import com.ouken.com.R;
//import com.ouken.tool.MplayerTool;
import com.ouken.tool.MyApp;
import com.vick.com.ChallengerwaitingActivity;
import com.vick.com.DrawingActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.IBinder;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ImageView;

public class GameRoomManagerActivity extends Activity {
	
	/**------------------elements define area--------------------------*/
	private MyApp appState;
	private SharedPreferences userInfo;
	//private MplayerTool mplayerTool ;
	private TextView roomName;
	private TextView memNum;
	private ImageView my_image;
	private TextView myName;
	private TextView myScore;
	private ImageButton userImagebt[] = new ImageButton[4];
	private TextView user_name[] = new TextView[4];
	private TextView user_Score[] = new TextView[4];
	private TextView user_ready[] = new TextView[4];
	private ProgressBar user_pgbar[] = new ProgressBar[4];
	
	private Button but_startgame;
	private Button but_user_kick[] = new Button[4];
	private Button but_quit;
	
	private static final char READY = '0';
	private static final char UNREADY = '1';
	private static final char EMPTY = '2';
	private static final char INACTIVE = '3';
	private static final char MANAGER = '4';
	/**------------------elements define area over--------------------------*/
	
	private Context context;
	private GameRoomManagerUpdateReceiver gameRoomManagerUpdateReceiver;
	private RefreshGameRoomManagerService refreshGameRoomManagerService = null;
	private IntentFilter filter;
	private Intent intentToRefreshService;
	

	
	private ServiceConnection connection = new ServiceConnection(){

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			refreshGameRoomManagerService = ((RefreshGameRoomManagerService.LocalBinder) service).getService();
		}

		@Override
		public void onServiceDisconnected(ComponentName name) {
			refreshGameRoomManagerService = null;
		}
		
	};
	
	/**-----------------initview when created-----------------*/
	private void initView(){
				
		userInfo  = getSharedPreferences("user_info", 0);
		appState = ((MyApp)getApplicationContext());
		appState.setGRcounterZ();
		//appState.setMusic(userInfo.getString("MUSIC", "ON").equals("ON"));
		appState.setListActivities(new ArrayList());
		appState.addActivity(GameRoomManagerActivity.this);
		
		roomName = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_roomName);
        memNum = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_memnum);
        my_image = (ImageView)findViewById(R.id.gameRoomManagerActivity_imageView_imageMe);
        myName = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_myName);
    	myScore = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_myScore);
    	userImagebt[0] = (ImageButton)findViewById(R.id.gameRoomManagerActivity_imageButton_imageUser1);
    	user_name[0] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user1Name);
    	user_Score[0] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user1Score);
    	user_ready[0] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user1Ready);
    	userImagebt[1] = (ImageButton)findViewById(R.id.gameRoomManagerActivity_imageButton_imageUser2);
    	user_name[1] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user2Name);
    	user_Score[1] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user2Score);
    	user_ready[1] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user2Ready);
    	userImagebt[2] = (ImageButton)findViewById(R.id.gameRoomManagerActivity_imageButton_imageUser3);
    	user_name[2] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user3Name);
    	user_Score[2] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user3Score);
    	user_ready[2] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user3Ready);
    	userImagebt[3] = (ImageButton)findViewById(R.id.gameRoomManagerActivity_imageButton_imageUser4);
    	user_name[3]= (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user4Name);
    	user_Score[3] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user4Score);
    	user_ready[3] = (TextView)findViewById(R.id.gameRoomManagerActivity_textView_user4Ready);
    	
    	but_startgame = (Button)findViewById(R.id.gameRoomManagerActivity_button_startGame);
    	but_user_kick[0] = (Button)findViewById(R.id.gameRoomManagerActivity_button_kickUser1);
    	but_user_kick[1] = (Button)findViewById(R.id.gameRoomManagerActivity_button_kickUser2);
    	but_user_kick[2] = (Button)findViewById(R.id.gameRoomManagerActivity_button_kickUser3);
    	but_user_kick[3] = (Button)findViewById(R.id.gameRoomManagerActivity_button_kickUser4);
    	but_quit = (Button)findViewById(R.id.gameRoomManagerActivity_button_quitRoom);
    	
    	user_pgbar[0] = (ProgressBar)findViewById(R.id.gameRoomManagerActivity_loading_process_dialog_progressBar1);
    	user_pgbar[1] = (ProgressBar)findViewById(R.id.gameRoomManagerActivity_loading_process_dialog_progressBar2);
    	user_pgbar[2] = (ProgressBar)findViewById(R.id.gameRoomManagerActivity_loading_process_dialog_progressBar3);
    	user_pgbar[3] = (ProgressBar)findViewById(R.id.gameRoomManagerActivity_loading_process_dialog_progressBar4);
        
    	but_startgame.setOnClickListener(gameRoom_listener);
    	but_user_kick[0].setOnClickListener(gameRoom_listener);
    	but_user_kick[1].setOnClickListener(gameRoom_listener);
    	but_user_kick[2].setOnClickListener(gameRoom_listener);
    	but_user_kick[3].setOnClickListener(gameRoom_listener);
    	but_quit.setOnClickListener(gameRoom_listener);
    	userImagebt[0].setOnClickListener(gameRoom_ibtlistener);
    	userImagebt[1].setOnClickListener(gameRoom_ibtlistener);
    	userImagebt[2].setOnClickListener(gameRoom_ibtlistener);
    	userImagebt[3].setOnClickListener(gameRoom_ibtlistener);
    	
    	but_user_kick[0].setVisibility(View.GONE);
    	but_user_kick[1].setVisibility(View.GONE);
    	but_user_kick[2].setVisibility(View.GONE);
    	but_user_kick[3].setVisibility(View.GONE);
    	
    	user_pgbar[0].setVisibility(View.VISIBLE);
    	user_pgbar[1].setVisibility(View.VISIBLE);
    	user_pgbar[2].setVisibility(View.VISIBLE);
    	user_pgbar[3].setVisibility(View.VISIBLE);
    	
    	userImagebt[0].setEnabled(false);
    	userImagebt[1].setEnabled(false);
    	userImagebt[2].setEnabled(false);
    	userImagebt[3].setEnabled(false);
		
    	context = GameRoomManagerActivity.this;
    	//mplayerTool = new MplayerTool(GameRoomManagerActivity.this);
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gameroom_manager);                
        initView();
        
		/**----------owner's zone-------------**/
        roomName.setText(appState.getRoomName());
		memNum.setText(appState.getMem());
		myName.setText(appState.getNickName());
		myScore.setText(appState.getTotalScore() + "pt");
		my_image.setImageBitmap(appState.getImg());
		
		/**----------bind service-------------**/
		intentToRefreshService = new Intent("com.serive.refreshGameRoomManager");
		
        gameRoomManagerUpdateReceiver = new GameRoomManagerUpdateReceiver();
        filter= new IntentFilter();
        filter.addAction("com.gameRoomManagerUpdateReceiver");
        registerReceiver(gameRoomManagerUpdateReceiver, filter);
        
        //bindService(new Intent(this,RefreshGameRoomManagerService.class), connection, Context.BIND_AUTO_CREATE);
    }
    
    private View.OnClickListener gameRoom_ibtlistener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			
			ImageButton gameRoom_button = (ImageButton)v;
			SoundPlayer.playSound(R.raw.keypress_common);
			//mplayerTool.playButtonPressed(context);
			
			switch(gameRoom_button.getId()){
			case R.id.gameRoomManagerActivity_imageButton_imageUser1:
				switch(appState.getPlayerList().get(1).getState().charAt(0)){
				//empty
				case EMPTY:
					new AsynDelLim(context, roomName,appState.getUserEmail()).execute();
					break;
					
				//inactive
				case INACTIVE:

					new AsynAddLim(context, roomName,appState.getUserEmail()).execute();
					break;
				}
				break;
				
			case R.id.gameRoomManagerActivity_imageButton_imageUser2:
				switch(appState.getPlayerList().get(2).getState().charAt(0)){
				//empty
				case EMPTY:
					new AsynDelLim(context, roomName,appState.getUserEmail()).execute();
					break;
					
				//inactive
				case INACTIVE:
					new AsynAddLim(context, roomName,appState.getUserEmail()).execute();
					break;
				}
				break;
				
			case R.id.gameRoomManagerActivity_imageButton_imageUser3:
				switch(appState.getPlayerList().get(3).getState().charAt(0)){
				//empty
				case EMPTY:
					new AsynDelLim(context, roomName,appState.getUserEmail()).execute();
					break;
					
				//inactive
				case INACTIVE:
					new AsynAddLim(context, roomName,appState.getUserEmail()).execute();
					break;
				}
				break;
				
			case R.id.gameRoomManagerActivity_imageButton_imageUser4:
				switch(appState.getPlayerList().get(4).getState().charAt(0)){
				//empty
				case EMPTY:
					new AsynDelLim(context, roomName,appState.getUserEmail()).execute();
					break;
					
				//inactive
				case INACTIVE:
					new AsynAddLim(context, roomName,appState.getUserEmail()).execute();
					break;
				}
			}
			
		}
	};
    
    private View.OnClickListener gameRoom_listener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			
			Button gameRoom_button = (Button)v;
			SoundPlayer.playSound(R.raw.keypress_common);
			//mplayerTool.playButtonPressed(context);
			
        	
			switch(gameRoom_button.getId()){
			case R.id.gameRoomManagerActivity_button_startGame:
					new AsynStartGame(context,roomName,appState.getUserEmail()).execute();
					break;
				
			case R.id.gameRoomManagerActivity_button_kickUser1:
				AlertDialog_ok_cancel myDialog1 = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to kick " + user_name[0].getText().toString()+ "?");
				final AlertDialog kicked1 = myDialog1.AlertDialog_ok_cancel_show();
				
					myDialog1.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
						@Override  
					    public void onClick(View v) {  
							SoundPlayer.playSound(R.raw.keypress_common);
							kicked1.dismiss();
							/* User clicked OK so do some stuff */ 
	                    	new AsynKick(context, roomName,appState.getPlayerList().get(1).getUserEmail()).execute();
							} 
						}
					); 
					
		        	myDialog1.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
						@Override  
					    public void onClick(View v) {  
							SoundPlayer.playSound(R.raw.keypress_common);
							 /* User clicked Cancel so do some stuff */
							kicked1.cancel();
							} 
						}
					);
				break;
				
			case R.id.gameRoomManagerActivity_button_kickUser2:
				AlertDialog_ok_cancel myDialog2 = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to kick " + user_name[1].getText().toString()+ "?");
				final AlertDialog kicked2 = myDialog2.AlertDialog_ok_cancel_show();
				myDialog2.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) {  
						SoundPlayer.playSound(R.raw.keypress_common);
						kicked2.dismiss();
						/* User clicked OK so do some stuff */ 
                    	new AsynKick(context, roomName,appState.getPlayerList().get(2).getUserEmail()).execute();
						} 
					}
				); 
				
	        	myDialog2.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) { 
						SoundPlayer.playSound(R.raw.keypress_common);
						 /* User clicked Cancel so do some stuff */
                    	kicked2.cancel();
						} 
					}
				);
				break;
				
			case R.id.gameRoomManagerActivity_button_kickUser3:
				AlertDialog_ok_cancel myDialog3 = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to kick " + user_name[2].getText().toString()+ "?");
				final AlertDialog kicked3 = myDialog3.AlertDialog_ok_cancel_show();
				myDialog3.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) { 
						SoundPlayer.playSound(R.raw.keypress_common);
						kicked3.dismiss();
						/* User clicked OK so do some stuff */ 
                    	new AsynKick(context, roomName,appState.getPlayerList().get(3).getUserEmail()).execute();
						} 
					}
				); 
				
	        	myDialog3.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) {  
						SoundPlayer.playSound(R.raw.keypress_common);
						 /* User clicked Cancel so do some stuff */
                    	kicked3.cancel();
						} 
					}
				);
				break;
				
			case R.id.gameRoomManagerActivity_button_kickUser4:
				AlertDialog_ok_cancel myDialog4 = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to kick " + user_name[3].getText().toString()+ "?");
				final AlertDialog kicked4 = myDialog4.AlertDialog_ok_cancel_show();
				myDialog4.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) { 
						SoundPlayer.playSound(R.raw.keypress_common);
						kicked4.dismiss();
						/* User clicked OK so do some stuff */ 
                    	new AsynKick(context, roomName,appState.getPlayerList().get(4).getUserEmail()).execute();
						} 
					}
				); 
				
	        	myDialog4.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) {  
						SoundPlayer.playSound(R.raw.keypress_common);
						 /* User clicked Cancel so do some stuff */
                    	kicked4.cancel();
						} 
					}
				);
				break;
				
			case R.id.gameRoomManagerActivity_button_quitRoom:
				AlertDialog_ok_cancel myDialog = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to \nquit from this room?");
				final AlertDialog quit = myDialog.AlertDialog_ok_cancel_show();
				myDialog.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) {  
						SoundPlayer.playSound(R.raw.keypress_common);
						try{
                			unbindService(connection);
                		}catch(Exception e){
                			System.out.print(e.toString());
                		}
                		quit.dismiss();
                    	new AsynManagerQuitFR(context,roomName,appState.getUserEmail()).execute();
						} 
					}
				); 
				
	        	myDialog.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
					@Override  
				    public void onClick(View v) {  
						SoundPlayer.playSound(R.raw.keypress_common);
						 /* User clicked Cancel so do some stuff */
						quit.cancel();
						} 
					}
				);
				break;
			}
		}
	};
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
        	SoundPlayer.playSound(R.raw.keypress_common);
        	AlertDialog_ok_cancel myDialog = new AlertDialog_ok_cancel(GameRoomManagerActivity.this,"Are you sure to \nquit from this room?");
        	final AlertDialog now = myDialog.AlertDialog_ok_cancel_show();
        	
        	myDialog.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
				@Override  
			    public void onClick(View v) {  
					SoundPlayer.playSound(R.raw.keypress_common);
					try{
            			unbindService(connection);
            		}catch(Exception e){
            			System.out.print(e.toString());
            		}
            		now.dismiss();
                	new AsynManagerQuitFR(context,roomName,appState.getUserEmail()).execute();
				}
				}
			); 
			
        	myDialog.getCancel_btn_can().setOnClickListener(new View.OnClickListener(){
				@Override  
			    public void onClick(View v) {  
					SoundPlayer.playSound(R.raw.keypress_common);
					 /* User clicked Cancel so do some stuff */
                	now.cancel();
					} 
				}
			);
			
        }
        return false;
    }
	
	@Override
	protected void onResume() {
		super.onResume();
		appState.setGRcounterZ();
		appState.setClearPlayerInfo();
		bindService(new Intent(this,RefreshGameRoomManagerService.class), connection, Context.BIND_AUTO_CREATE);
		System.out.println("GameRoomManagerActivity onResume");
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		try{
			unbindService(connection);
		}catch(Exception e){
			System.out.print(e.toString());
		}
		System.out.println("GameRoomManagerActivity onPause");
	}
	
	@Override
	protected void onDestroy() {
		 super.onDestroy();
		 unregisterReceiver(gameRoomManagerUpdateReceiver);
		 System.out.println("GameRoomManagerActivity onDestroy");
	}

	/**-------------------do refresh ope-------------*/
	public class GameRoomManagerUpdateReceiver extends BroadcastReceiver{
	    
		@Override
		public void onReceive(Context arg0, Intent arg1) {
			System.out.println("I'm GameRoomManagerActivity reciever");
			
			String action = arg1.getAction();
			
			//do update
			if(action.equals("com.gameRoomManagerUpdateReceiver")){
				Bundle bundle = arg1.getExtras();
				if(bundle !=null){
					
					String changes = bundle.getString("changes");
					ArrayList<PlayerInfo> player = new ArrayList<PlayerInfo>(appState.getPlayerList());
					PlayerInfo tempPlayer = new PlayerInfo();
					
					//----------check if refresh----------//
					switch(changes.charAt(0)){
					case '1':
						//____________started the game___________//
						if(appState.getPlayerByNum(0).getRole().equals("provider")){
							Intent intentForManager = new Intent(context, DrawingActivity.class); 
							intentForManager.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
							System.out.print("Started provider's page");
							startActivity(intentForManager);
							GameRoomManagerActivity.this.finish();
							overridePendingTransition(0, 0);
							return;
						}
						else{
							Intent intentForManager = new Intent(context, ChallengerwaitingActivity.class); 
							intentForManager.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
							System.out.print("Started challenger's page");
							startActivity(intentForManager);
							GameRoomManagerActivity.this.finish();
							overridePendingTransition(0, 0);
							return;
						}
					case '2':
						//************double log in************//
						try{
							unbindService(connection);
						}catch(Exception e){
							System.out.print(e.toString());
						}
						
						AlertDialog_ok myDialog = new AlertDialog_ok(GameRoomManagerActivity.this,"Sorry~>.<~ \nDuable login now~");
			        	final AlertDialog now = myDialog.AlertDialog_ok_show();
					    
			        	myDialog.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
							@Override  
						    public void onClick(View v) {  
								SoundPlayer.playSound(R.raw.keypress_common);
								Intent intentNewAct = new Intent(context, LoginActivity.class);
								startActivity(intentNewAct);
								userInfo.edit().putString("AUTOLOGIN","NO").commit();
								now.dismiss();
								appState.killAllActivities();
								} 
							}
						);  	
						return;
					case '3':
						//************not the manager************//
						try{
							unbindService(connection);
						}catch(Exception e){
							System.out.print(e.toString());
						}
						
						AlertDialog_ok myDialogMAN = new AlertDialog_ok(GameRoomManagerActivity.this,"Sorry~>.<~ \nYou are not the manager~");
			        	final AlertDialog nowMAN = myDialogMAN.AlertDialog_ok_show();
					    
			        	myDialogMAN.getConfirm_btn_ok().setOnClickListener(new View.OnClickListener(){
							@Override  
						    public void onClick(View v) {  
								SoundPlayer.playSound(R.raw.keypress_common);
								Intent intentNewAct = new Intent(context, LoginActivity.class);
								startActivity(intentNewAct);
								userInfo.edit().putString("AUTOLOGIN","NO").commit();
								nowMAN.dismiss();
								appState.killAllActivities();
								} 
							}
						);  	
						return;
					}
					
					//----------first time refresh----------//
					if(appState.getRefreshGRcounter() == 0){
						memNum.setText(appState.getMem());
						//____________set users' view__________//
						for(int i = 0; i< 4; i++)
						{
							tempPlayer = player.get(i+1);
							
							//user's state
							switch(tempPlayer.getState().charAt(0)){
							case EMPTY:
								//change image to empty
								userImagebt[i].setImageResource(R.drawable.gameroom_empty_imb);
								user_ready[i].setText(" ");
								user_name[i].setText("Empty Place");
								user_Score[i].setText(" ");
								userImagebt[i].setEnabled(true);
								but_user_kick[i].setVisibility(View.GONE);
								break;
								
							case INACTIVE:
								userImagebt[i].setImageResource(R.drawable.gameroom_xpeople_imb);
								user_ready[i].setText(" ");
								user_name[i].setText("Inactive Place");
								user_Score[i].setText(" ");
								userImagebt[i].setEnabled(true);
								but_user_kick[i].setVisibility(View.GONE);
								break;
								
							case READY:
								userImagebt[i].setImageBitmap(tempPlayer.getImg());
								but_user_kick[i].setVisibility(View.VISIBLE); //set kick button visible
								user_name[i].setText(tempPlayer.getNickName());
								user_Score[i].setText(tempPlayer.getTotalScore()+ "pt");
								user_ready[i].setText("Ready");
								userImagebt[i].setEnabled(false);
								break;
								
							case UNREADY:
								userImagebt[i].setImageBitmap(tempPlayer.getImg());
								but_user_kick[i].setVisibility(View.VISIBLE); //set kick button visible
								user_name[i].setText(tempPlayer.getNickName());
								user_Score[i].setText(tempPlayer.getTotalScore()+ "pt");
								user_ready[i].setText("UnReady");
								userImagebt[i].setEnabled(false);
								break;
							}
							user_pgbar[i].setVisibility(View.GONE);
						}
						appState.addGRcounter();
					}
					
					//-------------do refresh-----------------//
					else{
						//_____________refresh playlist__________//
						if(changes.contains("1") || changes.contains("2")){
							memNum.setText(appState.getMem());
							
							for (int i = 0; i < 4; i++) {
								
								//already existed person, only change the state
								tempPlayer = player.get(i+1);
								
								switch(changes.charAt(i+1)){
								case '1':
									//user's state
									switch(tempPlayer.getState().charAt(0)){
									case READY:
										user_ready[i].setText("Ready");
										but_user_kick[i].setVisibility(View.VISIBLE);
										break;
										
									case UNREADY:
										user_ready[i].setText("UnReady");
										but_user_kick[i].setVisibility(View.VISIBLE);
										break;
									}
									break;
									
								case '2':
									//new person or kicked person or quit person, update all
									//switch user's state
									switch (tempPlayer.getState().charAt(0)){
										case EMPTY:
											//change image to empty
											userImagebt[i].setImageResource(R.drawable.gameroom_empty_imb);
											but_user_kick[i].setVisibility(View.GONE);
											user_ready[i].setText(" ");
											user_name[i].setText("Empty Place");
											user_Score[i].setText(" ");
											userImagebt[i].setEnabled(true);
											break;
											
										case INACTIVE:
											userImagebt[i].setImageResource(R.drawable.gameroom_xpeople_imb);
											but_user_kick[i].setVisibility(View.GONE);
											user_ready[i].setText(" ");
											user_name[i].setText("Inactive Place");
											user_Score[i].setText(" ");
											userImagebt[i].setEnabled(true);
											break;
											
										case READY:
											userImagebt[i].setImageBitmap(tempPlayer.getImg());
											but_user_kick[i].setVisibility(View.VISIBLE); //set kick button visible
											user_name[i].setText(tempPlayer.getNickName());
											user_Score[i].setText(tempPlayer.getTotalScore()+ "pt");
											user_ready[i].setText("Ready");
											userImagebt[i].setEnabled(false);
											break;
											
										case UNREADY:
											userImagebt[i].setImageBitmap(tempPlayer.getImg());
											but_user_kick[i].setVisibility(View.VISIBLE); //set kick button visible
											user_name[i].setText(tempPlayer.getNickName());
											user_Score[i].setText(tempPlayer.getTotalScore()+ "pt");
											user_ready[i].setText("UnReady");
											userImagebt[i].setEnabled(false);
											break;
									}
									break;
								}
							}//for to find over
					      }//if have changed, refresh over
					}//refresh over
				}//have result over
			}//receive message over
		}//function over
	}//class over	
	
}

